package com.study.pojo;

import com.study.bind.MapperRegistry;
import com.study.sqlSession.SqlSessionImpl;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

public class Configuration {

    /**
     * 数据源
     */
    private DataSource dataSource;

    private Map<String, MappedStatement> mappedStatementMap = new HashMap<>();

    protected final MapperRegistry mapperRegistry = new MapperRegistry(this);

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public Map<String, MappedStatement> getMappedStatementMap() {
        return mappedStatementMap;
    }

    public void setMappedStatementMap(Map<String, MappedStatement> mappedStatementMap) {
        this.mappedStatementMap = mappedStatementMap;
    }

    public MapperRegistry getMapperRegistry() {
        return mapperRegistry;
    }

    public <T> void addMapper(Class<T> type) {
        mapperRegistry.addMapper(type);
    }

    public <T> T getMapper(Class<T> type, SqlSessionImpl sqlSession) throws Exception {
        return mapperRegistry.getMapper(type, sqlSession);
    }
}
